package com.liuqi.aiagent.transfer.mapstruct;

import com.liuqi.aiagent.transfer.dto.AgentEditDto;
import com.liuqi.aiagent.transfer.dto.AgentPublishUpdateDto;
import com.liuqi.aiagent.transfer.dto.AgentSaveDto;
import com.liuqi.aiagent.transfer.entity.Agent;
import com.liuqi.aiagent.transfer.vo.AgentInfoVo;
import com.liuqi.aiagent.transfer.vo.AgentVo;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author liuqi
 * @date 2025/7/16
 **/
@Mapper
public interface AgentMapStruct {
    AgentMapStruct INSTANCE = Mappers.getMapper(AgentMapStruct.class);

    @Mapping(target = "updateTime", source = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    AgentVo toVo(Agent agent);

    @Mappings({
            @Mapping(target = "updateTime", source = "updateTime", dateFormat = "yyyy-MM-dd HH:mm:ss"),
            @Mapping(target = "llmModelParameter",
                    expression = "java(com.alibaba.fastjson.JSON.parseObject(agent.getLlmModelParameter(), " +
                            "com.liuqi.aiagent.transfer.common.LLMModelParameter.class))")
    })
    AgentInfoVo toInfoVo(Agent agent);

    List<AgentVo> toVos(List<Agent> agents);

    Agent from(AgentSaveDto agentSaveDto);

    Agent from(AgentEditDto agentEditDto);

    @Mappings({
            @Mapping(target = "llmModelParameter",
                    expression = "java(com.alibaba.fastjson.JSON.toJSONString(updateDto.getLlmModelParameter(), " +
                            "com.alibaba.fastjson.serializer.SerializerFeature.WriteMapNullValue))"),
            @Mapping(target = "id", source = "agentId")
    })
    Agent from(AgentPublishUpdateDto updateDto);
}
